/* 相应器单例 */

class _CEventMgr {
    constructor() {
        this._eventlist = {};//事件表
        this._num = 0;
    }

    on(strEvtname, cbHandle) {
        this._eventlist[strEvtname] = cbHandle;
        this._num = this._eventlist.length;
    }

    remove(strEvtname) {
        delete this._eventlist[strEvtname];
    }

    clear() {
        this._eventlist = {};
    }

    dispatch(strEvtname) {
        if (this._eventlist.hasOwnProperty(strEvtname)) {
            var args = Array.prototype.slice.call(arguments);
            this._eventlist[strEvtname](args);
        }
    }
}

export default class CEvent {
    constructor() {
        this._inc = undefined;
    }

    static getInstance() {
        if (!this._inc) {
            this._inc = new _CEventMgr();
        }
        return this._inc;
    }
}